package com.skycode6.servlet;

import com.skycode6.bean.NewsBean;
import com.skycode6.dao.NoticeDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/noticefront.html")
public class NoticeFrontServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String p=req.getParameter("page");
        int page=1;
        if(p != null && p.equals("")){ //页面字符串不为空,强制转换为数字
            page = Integer.parseInt(p);
        }
        NoticeDao noticeDao = new NoticeDao();
        int totalPage = noticeDao.countPage();
        List<NewsBean> notice = noticeDao.getList(page);
//        List<Notice> notice = noticeDao.getList(page);
        //传递新闻信息给前端页面
        req.setAttribute("notice",notice);
        req.setAttribute("currentPage",page);//当前页数
        req.setAttribute("totalPage",totalPage);//总页数
        //加载网络前端页面
        req.getRequestDispatcher("front/noticeFrontList.jsp").forward(req,resp);
    }
}